package org.example.redisdemo.services;

import jakarta.annotation.Resource;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.stream.StreamListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RedisConsumer implements StreamListener<String, MapRecord<String, String, String>> {

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(MapRecord<String, String, String> message) {
        String key = message.getStream();
        Map<String, String> map = message.getValue();
        RecordId id = message.getId();
        System.out.println(map);
        redisTemplate.opsForStream().delete("teststream", id);
    }
}
